import ProList from '@ant-design/pro-list';
import { useEffect, useState } from 'react';
import { history } from 'umi';
import { TargetClassifyType } from '@/type';
import { getTargetFl } from '@/services';
import { message } from 'antd';

export default () => {
  const [dataSource, setDataSource] = useState<TargetClassifyType[]>();
  useEffect(() => {
    getData();
  }, []);
  const getData = async () => {
    const data = await getTargetFl();
    if (data.msg === '失败') {
      message.error(data.content);
      setDataSource([]);
    } else {
      setDataSource(data.content);
    }
  };
  return (
    <div style={{ display: 'flex', height: '100%' }}>
      <div
        style={{
          width: '100%',
          height: '100%',
          marginRight: '8px',
          background: '#fff',
        }}
      >
        <ProList<TargetClassifyType>
          defaultSize="small"
          onRow={({ id }) => {
            return {
              onClick: () => {
                history.push(`/search/fl/${id}`);
              },
            };
          }}
          rowKey="id"
          headerTitle="分类"
          dataSource={dataSource}
          showActions="always"
          key="id"
          metas={{
            title: {
              dataIndex: 'name',
            },
          }}
        />
      </div>
    </div>
  );
};
